﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.UI;
using System.Windows.Media.Imaging;
using System.Xml.Linq;

using System.IO;
using System.Diagnostics;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;

namespace BIM.XML3DExport
{
    public class XML3DExportUI : IExternalApplication
    {
        public static string AddInPath = typeof(XML3DExportUI).Assembly.Location;

        static string ButtonIconsFolder = Path.GetDirectoryName(AddInPath) + "\\Res";

        // Methods
        static XML3DExportUI()
        {
            AddInPath = typeof(XML3DExportUI).Assembly.Location;
        }

        #region IExternalApplication Members

        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;

            throw new NotImplementedException();
        }

        public Result OnStartup(UIControlledApplication application)
        {
            // Create a custom ribbon tab   
            String tabName = "3DXML-Exporter";
            application.CreateRibbonTab(tabName);
            string directoryName = Path.GetDirectoryName(AddInPath);

            RibbonPanel toolsRibbonPanel = application.CreateRibbonPanel(tabName, "3DXML Exporter");

            PushButton converterButton = toolsRibbonPanel.AddItem(
               new PushButtonData("3DXML Exporter", "3DXML Exporter for Revit",
                   directoryName + @"\XML3DExport.dll",
                   "BIM.XML3DExport.XML3DExportCommand")) as PushButton;
            converterButton.LongDescription = "Revit to 3DXML Converter";
            converterButton.ToolTip = "The 3DXML Exporter for Revit is designed to produce a stereolithography file (3DXML) of your building model.";
            converterButton.LongDescription = "The 3DXML Exporter for the Autodesk Revit Platform is a proof-of-concept project designed to create an 3DXML file from a 3D building information model, thereby enabling easier 3D printing.";

            Uri url3DViewImage = new Uri(Path.Combine(ButtonIconsFolder, "3DXMLExporter_32.png"), UriKind.Absolute);
            BitmapImage url3DViewLargeImage = new BitmapImage(url3DViewImage);
            converterButton.LargeImage = url3DViewLargeImage;

            return Result.Succeeded;

            throw new NotImplementedException();
        }

        #endregion
    }
}
